<?php

namespace backend\services\common;

use backend\extensions\ApiBaseService;
use backend\models\goods\cate\GoodsCate;
use backend\models\active\ActiveCoupon;
use common\models\active\ActivePromotionModel;


/**
 * 选项
 */
class OptionService extends ApiBaseService
{
    /**
     * 获取选项
     * @param array $keys
     * @return array
     */
    public static function getOptions($keys)
    {
        $result = [];
        foreach ($keys as $key) {
            if (!method_exists(self::class, $key)) {
                continue;
            }
            $result[$key] = self::{$key}();
        }

        return $result;
    }

   

    /**
     * 分类
     * @return array
     */
    // public static function cates()
    // {
    //     return Cate::find()->select(['id', 'name'])->asArray()->all();
    // }
    /**
     * 分类
     * @return array
     */
    public static function cateTrees()
    {
        $list = GoodsCate::find()->select(['*', 'id value', 'name label'])->asArray()->all();
        return $list;
    }

   
    /**
     * 券列表
     * @return array
     */
    public static function couponOptions()
    {
        $list = ActiveCoupon::find()
            ->select(['id', 'name'])->orderBy(['id' => SORT_ASC])->asArray()->all();
        $result = [];
        foreach ($list as $item) {
            $result[] = [
                'value' => $item['id'],
                'label' => '【'. $item['id'] .'】'. $item['name'],
            ];
        }

        return $result;
    }
    
   
    /**
     * 活动
     * @return array
     */
    public static function activeOptions()
    {
        $typeOpts = [];

        $types = ActivePromotionModel::$type;
        foreach ($types as $id => $name) {
            $typeOpts[] = ['id' => $id, 'name' => $name];
        }

        return [
            'type' => $typeOpts
        ];
    }
}
